use utf8;
package iSOCK::Schema::Bugzilla::Result::Product;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

=head1 NAME

iSOCK::Schema::Bugzilla::Result::Product

=cut

use strict;
use warnings;

use Moose;
use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';

=head1 COMPONENTS LOADED

=over 4

=item * L<DBIx::Class::InflateColumn::DateTime>

=back

=cut

__PACKAGE__->load_components("InflateColumn::DateTime");

=head1 TABLE: C<products>

=cut

__PACKAGE__->table("products");

=head1 ACCESSORS

=head2 id

  data_type: 'smallint'
  is_auto_increment: 1
  is_nullable: 0

=head2 name

  data_type: 'varchar'
  is_nullable: 0
  size: 64

=head2 classification_id

  data_type: 'smallint'
  default_value: 1
  is_foreign_key: 1
  is_nullable: 0

=head2 description

  data_type: 'mediumtext'
  is_nullable: 0

=head2 isactive

  data_type: 'tinyint'
  default_value: 1
  is_nullable: 0

=head2 defaultmilestone

  data_type: 'varchar'
  default_value: '---'
  is_nullable: 0
  size: 20

=head2 allows_unconfirmed

  data_type: 'tinyint'
  default_value: 1
  is_nullable: 0

=cut

__PACKAGE__->add_columns(
  "id",
  { data_type => "smallint", is_auto_increment => 1, is_nullable => 0 },
  "name",
  { data_type => "varchar", is_nullable => 0, size => 64 },
  "classification_id",
  {
    data_type      => "smallint",
    default_value  => 1,
    is_foreign_key => 1,
    is_nullable    => 0,
  },
  "description",
  { data_type => "mediumtext", is_nullable => 0 },
  "isactive",
  { data_type => "tinyint", default_value => 1, is_nullable => 0 },
  "defaultmilestone",
  {
    data_type => "varchar",
    default_value => "---",
    is_nullable => 0,
    size => 20,
  },
  "allows_unconfirmed",
  { data_type => "tinyint", default_value => 1, is_nullable => 0 },
);

=head1 PRIMARY KEY

=over 4

=item * L</id>

=back

=cut

__PACKAGE__->set_primary_key("id");

=head1 UNIQUE CONSTRAINTS

=head2 C<products_name_idx>

=over 4

=item * L</name>

=back

=cut

__PACKAGE__->add_unique_constraint("products_name_idx", ["name"]);

=head1 RELATIONS

=head2 bugs

Type: has_many

Related object: L<iSOCK::Schema::Bugzilla::Result::Bug>

=cut

__PACKAGE__->has_many(
  "bugs",
  "iSOCK::Schema::Bugzilla::Result::Bug",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 classification

Type: belongs_to

Related object: L<iSOCK::Schema::Bugzilla::Result::Classification>

=cut

__PACKAGE__->belongs_to(
  "classification",
  "iSOCK::Schema::Bugzilla::Result::Classification",
  { id => "classification_id" },
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);

=head2 components

Type: has_many

Related object: L<iSOCK::Schema::Bugzilla::Result::Component>

=cut

__PACKAGE__->has_many(
  "components",
  "iSOCK::Schema::Bugzilla::Result::Component",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 flagexclusions

Type: has_many

Related object: L<iSOCK::Schema::Bugzilla::Result::Flagexclusion>

=cut

__PACKAGE__->has_many(
  "flagexclusions",
  "iSOCK::Schema::Bugzilla::Result::Flagexclusion",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 flaginclusions

Type: has_many

Related object: L<iSOCK::Schema::Bugzilla::Result::Flaginclusion>

=cut

__PACKAGE__->has_many(
  "flaginclusions",
  "iSOCK::Schema::Bugzilla::Result::Flaginclusion",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 group_control_maps

Type: has_many

Related object: L<iSOCK::Schema::Bugzilla::Result::GroupControlMap>

=cut

__PACKAGE__->has_many(
  "group_control_maps",
  "iSOCK::Schema::Bugzilla::Result::GroupControlMap",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 milestones

Type: has_many

Related object: L<iSOCK::Schema::Bugzilla::Result::Milestone>

=cut

__PACKAGE__->has_many(
  "milestones",
  "iSOCK::Schema::Bugzilla::Result::Milestone",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 versions

Type: has_many

Related object: L<iSOCK::Schema::Bugzilla::Result::Version>

=cut

__PACKAGE__->has_many(
  "versions",
  "iSOCK::Schema::Bugzilla::Result::Version",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);


# Created by DBIx::Class::Schema::Loader v0.07012 @ 2011-11-21 16:12:36
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TISHT1hzT1zFciyhxU5l3A

use iSOCK::Schema::Tricks;

sub sorted_versions {
  my ( $self ) = @_;
  
  return sort map { iSOCK::Schema::Tricks->version_to_storage ( $_ ) } grep { $_ ne 'unspecified' } map { $_->value } $self->versions;
}

sub last_version {
  my ( $self ) = @_;
  
  my @versions = $self->sorted_versions;
  
  return $versions[-1] if @versions;
  
  return;
}

sub bug_list_url {
  my ( $self, $option ) = @_;
  
  my $url = $option->{root} . '/buglist.cgi?product=' . $self->name;
  
  $url .= "&bug_status=__$option->{status}__" if $option->{status};
  $url .= "&version=$option->{version}"       if $option->{version};
  
  return $url;
}

sub bug_list_a {
  my ( $self, $option ) = @_;
  
  return { tag => 'a', href => $self->bug_list_url ( $option ), title => ( $option->{title} || $self->description ), content => ( $option->{content} || $self->id ) };
}

sub bug_list_html_a {
  my ( $self, $option ) = @_;
  
  return "<a href=\"$_->{href}\" title=\"$_->{title}\">$_->{content}</a>" for $self->bug_list_a ( $option );
}

# You can replace this text with custom code or comments, and it will be preserved on regeneration
__PACKAGE__->meta->make_immutable;
1;
